package m202406.d11;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/11 18:20
 */
public class Q152 {
    public int maxProduct(int[] nums) {
        int[] minDp = new int[nums.length];
        int[] maxDp = new int[nums.length];

        minDp[0] = nums[0];
        maxDp[0] = nums[0];

        int max = nums[0];

        for (int i = 1; i < nums.length; i++) {
            minDp[i] = Math.min(nums[i], Math.min(minDp[i - 1] * nums[i], maxDp[i - 1] * nums[i]));
            maxDp[i] = Math.max(nums[i], Math.max(minDp[i - 1] * nums[i], maxDp[i - 1] * nums[i]));
            max = Math.max(maxDp[i], max);
        }
        return max;
    }
}
